package co.edu.usbcali.rebio.presentation.backEndBeans;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import com.icesoft.faces.context.effects.JavascriptContext;

public class RebReporteCuatro {
	
	public String action_generarReporte(){
		
		FacesContext fc = FacesContext.getCurrentInstance();
		ExternalContext ec = fc.getExternalContext();
		HttpServletRequest sr = ((HttpServletRequest)ec.getRequest());
		String scheme = sr.getScheme();
		String serverName = sr.getServerName();
		int port = sr.getServerPort();
		String contextPath = sr.getContextPath();
		
		String url = scheme+"://"+serverName+":"+port+contextPath;
		
		//String factura = txtFactura.getValue().toString();
		
		//String reportParams = "factura="+factura;
		//String reportParams = "nit="+factura+"&p2=567";
	
		
		//reportParams +="numCot="+txtNoCotizacion.getValue().toString();
		
		
		String params = 
			  "'"+
			  url+"/servlet/ReporteCuatro?"+
			  	//reportParams +
			  "', " +
			  "'reportWindow', " +
			  "'" +
			  "width=1024" +
			  ",height=768" +
			  ",status=no" +
			  ",toolbar=no" +
			  ",menubar=no" +
			  ",location=no" +
			  ",scrollbars=yes" +
			  "'"; 
		
//		System.out.println("window.open("+params+");");
		
		//llamar al servlet SatReportServlet
		//JavascriptContext.addJavascriptCall(fc,"window.open("+params+");");
		JavascriptContext.addJavascriptCall(fc,"location.href="+params+";");	
		
		
		
		return "";
		
	}

	public String action_generarReporteXLS(){
	
		FacesContext fc = FacesContext.getCurrentInstance();
		ExternalContext ec = fc.getExternalContext();
		HttpServletRequest sr = ((HttpServletRequest)ec.getRequest());
		String scheme = sr.getScheme();
		String serverName = sr.getServerName();
		int port = sr.getServerPort();
		String contextPath = sr.getContextPath();
		
		String url = scheme+"://"+serverName+":"+port+contextPath;
		
		//String factura = txtFactura.getValue().toString();
		
		//String reportParams = "factura="+factura;
		//String reportParams = "nit="+factura+"&p2=567";
	
		
		//reportParams +="numCot="+txtNoCotizacion.getValue().toString();
		
		
		String params = 
			  "'"+
			  url+"/servlet/ReporteCuatroXLS?"+
			  	//reportParams +
			  "', " +
			  "'reportWindow', " +
			  "'" +
			  "width=1024" +
			  ",height=768" +
			  ",status=no" +
			  ",toolbar=no" +
			  ",menubar=no" +
			  ",location=no" +
			  ",scrollbars=yes" +
			  "'"; 
		
	//	System.out.println("window.open("+params+");");
		
		//llamar al servlet SatReportServlet
		//JavascriptContext.addJavascriptCall(fc,"window.open("+params+");");
		JavascriptContext.addJavascriptCall(fc,"location.href="+params+";");	
		
		
		
		return "";
	
	}

}
